package com.ruoyi.game.controller;

import java.security.Security;
import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.security.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.game.domain.GameInterface;
import com.ruoyi.game.service.IGameInterfaceService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 游戏接口Controller
 * 
 * @author qidian
 * @date 2022-05-05
 */
@RestController
@RequestMapping("/interface")
public class GameInterfaceController extends BaseController
{
    @Autowired
    private IGameInterfaceService gameInterfaceService;

    /**
     * 查询游戏接口列表
     */
    @RequiresPermissions("game:interface:list")
    @GetMapping("/list")
    public TableDataInfo list(GameInterface gameInterface)
    {
        startPage();
        List<GameInterface> list = gameInterfaceService.selectGameInterfaceList(gameInterface);
        return getDataTable(list);
    }

    /**
     * 导出游戏接口列表
     */
    @RequiresPermissions("game:interface:export")
    @Log(title = "游戏接口", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GameInterface gameInterface)
    {
        List<GameInterface> list = gameInterfaceService.selectGameInterfaceList(gameInterface);
        ExcelUtil<GameInterface> util = new ExcelUtil<GameInterface>(GameInterface.class);
        util.exportExcel(response, list, "游戏接口数据");
    }

    /**
     * 获取游戏接口详细信息
     */
    @RequiresPermissions("game:interface:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(gameInterfaceService.selectGameInterfaceById(id));
    }

    /**
     * 新增游戏接口
     */
    @RequiresPermissions("game:interface:add")
    @Log(title = "游戏接口", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GameInterface gameInterface)
    {
        gameInterface.setCreateBy("admin");
        return toAjax(gameInterfaceService.insertGameInterface(gameInterface));
    }

    /**
     * 修改游戏接口
     */
    @RequiresPermissions("game:interface:edit")
    @Log(title = "游戏接口", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GameInterface gameInterface)
    {
        return toAjax(gameInterfaceService.updateGameInterface(gameInterface));
    }

    /**
     * 删除游戏接口
     */
    @RequiresPermissions("game:interface:remove")
    @Log(title = "游戏接口", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(gameInterfaceService.deleteGameInterfaceByIds(ids));
    }
}
